package com.test.crawler.utils;

import lombok.Data;
import lombok.ToString;

import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Data
@ToString
public class SkuCustomAttr {
    private String text;
    private List <SkuCustomAttrVal> val;
    private String id;

    public SkuCustomAttr(String text, String propertyVal,String id) {
        this.text = text;
        this.id = id;
        this.val = new LinkedList <>();
        this.val.add(new SkuCustomAttrVal(propertyVal,id));
    }

    public boolean containsPropertyVal(String propertyVal) {
        Optional <SkuCustomAttrVal> optional = this.val.stream().filter(skuCustomAttrVal -> Objects.equals(skuCustomAttrVal.getVal(), propertyVal)).findAny();
        return optional.isPresent();
    }

    public void addPropertyVal(String propertyVal) {
        this.val.add(new SkuCustomAttrVal(propertyVal,id));
    }

}